package Pantallas;

import Main.MyApp;
import WSS.Wss;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.TouchEvent;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.container.GridFieldManager;
/**
 * A class extending the MainScreen class, which provides default standard
 * behavior for BlackBerry GUI applications.
 */
public final class PantallaProducto extends Pantalla
{
	private int width;
	private int height;
	private EditField ef;
	private GridFieldManager gfm2;
    /**
     * Creates a new MyScreen object
     */
    public PantallaProducto(){        
    	super();
    	width  = MyApp.getWidth();
    	height = MyApp.getHeight();
    	int j = 1;
    	gfm2 = new GridFieldManager(j+1, j, GridFieldManager.FIXED_SIZE);
		gfm2.setColumnPadding(5);
		 
		// Size the columns of the GridFieldManager. Make sure to calculate 
		// for the padding applied to the columns. 
		int columnWidth = (width / j) ;
		int rowHeight = (height / (j*3))  ;
		
		for(int i = 0; i < j; i++) {
			gfm2.setColumnProperty(i, GridFieldManager.FIXED_SIZE, columnWidth);
			gfm2.setRowProperty(i, GridFieldManager.FIXED_SIZE, rowHeight);
			} 
			
        ef = new EditField(Field.FIELD_HCENTER);
        ef.setLabel("Introduzca su Codigo: ");
        //
        gfm2.add(ef);
        
        ButtonField aceptar = new ButtonField("Aceptar"){
        	protected boolean navigationClick(int status, int time) {
        		// TODO Auto-generated method stub
        		//String pin = Integer.toHexString(DeviceInfo.getDeviceId());
        		//String num = Phone.getDevicePhoneNumber(true);
        			
        		return true;
        	}
        	protected boolean touchEvent( TouchEvent event ) 
        	{
        	   switch( event.getEvent()  ) 
        	   {
        	        case TouchEvent.CLICK:
        	           //handle click event here
        	        	//String pin = Integer.toHexString(DeviceInfo.getDeviceId());
                		//String num = Phone.getDevicePhoneNumber(true);
        	        	try{
        	        		int index = ef.getIndex();
        	        		String cod = ((EditField)gfm2.getField(index)).getText();
	        	        	//final String cod = ((EditField)gfm2.getField(index)).getText();
	                		Wss.getProducto(cod); 
        	        	}catch(Exception e){
        	        		Dialog.alert("P.Producto 1");
        	        	}
        	        return true;
        	        case TouchEvent.DOWN:
        	           //handle down event here 
        	        return true;
        	        case TouchEvent.MOVE:
        	           //handle move event here
        	        return true;
        	   }
        	   return false;
        	}
        }; 
        
        gfm2.add(aceptar);        
        add(gfm2);
    }
}
